package prepare;

import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: aleck
 * Date: 2007-10-17
 * Time: 0:44:27
 * To change this template use File | Settings | File Templates.
 */
public class MyDebugger {
  public static String concat(String[] cmd) {
    cmd[0] = new File(cmd[0]).getPath();

    StringBuilder cmdbuf = new StringBuilder(80);
    for (int i = 0; i < cmd.length; i++) {
      if (i > 0) {
        cmdbuf.append(' ');
      }
      String s = cmd[i];
      if (s.indexOf(' ') >= 0 || s.indexOf('\t') >= 0) {
        if (s.charAt(0) != '"') {
          cmdbuf.append('"');
          cmdbuf.append(s);
          if (s.endsWith("\\")) {
            cmdbuf.append("\\");
          }
          cmdbuf.append('"');
        } else if (s.endsWith("\"")) {
          /* The argument has already been quoted. */
          cmdbuf.append(s);
        } else {
          /* Unmatched quote for the argument. */
          throw new IllegalArgumentException();
        }
      } else {
        cmdbuf.append(s);
      }
    }
    String cmdstr = cmdbuf.toString();
    return cmdstr;
  }
}
